# -*- coding: utf-8 -*-
"""
Created on Tue Apr 23 15:42:17 2019

@author: jlani
"""

from garp import garp_find_e
from GarpMaker import GarpMaker
from data_manager import df_to_mats
from PermTester import PermTester

def permtest_simulate(N, L, e, sim_mode='b',perm_mode='r'):
    '''Function for running simulations using the rp permutation test.
    
    Takes arguments N, L, e, sim_mode, perm_mode
    
    N is the number of obs in the simulated data. L is the number of goods.
    e is the efficiency level for the simulated data. sim_mode takes argument 
    of either b or r. b will simulate from budget shares satisfying e-rptest
    while r will simulate rays satisfying e-rptest. 
    perm_mode takes either c, b, or r for consumption bundles, budget shares
    or rays. This determines what to shuffle in the permutation test.
    
    Will return a 2 item list. The first item is the e-score of the dataset.
    The second item is the p-value of the perm test.
    '''
    
    gm = GarpMaker(N,L,e,sim_mode)
    df = gm(1) #Simulate one dataset.
    C, P = df_to_mats(df,0) #This is the simulated data
    e_score = garp_find_e(C,P)
    
    pt = PermTester(C,P)
    p_value = pt('garp',perm_mode)
    return [ e_score, p_value ]



